/**
 * http配置
 */
// import axios from 'axios'
import axios from 'axios';
import router from '../../router/router';
import { Notification } from 'element-ui';
import { $local } from '../../assets/utils/utils';
// http request 添加拦截器
axios.interceptors.request.use(
    config => {
        config.headers.cstoken = $local('userInfo').token;
        return config;
    },
    err => {
        return Promise.reject(err);
    });

// http response 拦截器
axios.interceptors.response.use(
    response => {
        switch (response.data.errorCode) {
            case 1012:
                Notification({
                    title: '警告',
                    message: response.data.errorMsg,
                    type: 'warning'
                });
                window.localStorage.clear();
                // 切换到登录页面
                router.push('/login');
                break;
            case 1013:
                Notification({
                    title: '警告',
                    message: response.data.errorMsg,
                    type: 'warning'
                });
                window.localStorage.clear();
                // // 切换到登录页面
                router.push('/login');
                break;
            case 1014:
                Notification({
                    title: '警告',
                    message: response.data.errorMsg,
                    type: 'warning'
                });
                window.localStorage.clear();
                // 切换到登录页面
                router.push('/login');
                break;
            default:
                return response.data;
        }
    },
    error => {
        return Promise.reject(error.response.data)
    });

export default axios;
